﻿<div ms-controller="INFO">
    <div class="control-group">
        <label class="control-label">角色名称：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='text' data-rules="required|minlength=2|maxlength=50" ms-duplex="modelData.RoleName" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">角色描述：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.RoleDesp" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">是否管理员：</label>
        <div class="controls">
            <select class="input-xfat" ms-duplex="modelData.IsAdmin">
                <option value="0">否</option>
                <option value="1">是</option>
            </select>
            <div class="sui-msg msg-tips">
                <div class="msg-con">管理员无需设置权限</div>
                <s class="msg-icon"></s>
            </div>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            权限：
        </label>
        <div class="controls">

            <table class="sui-table table-bordered" id="authDT">
                <tbody>
                    <tr ms-repeat-el="authData">
                        <td>
                            <label class="checkbox-pretty inline menulvl1" ms-class="checked:el.issel>0?'checked':''" ms-attr-lid="el.ID">
                                <input type="checkbox"><span>{{el.MenuTxt}}</span>
                            </label>

                        </td>
                        <td>
                            <table class="sui-table table-bordered" >
                                <tr >
                                    <td ms-repeat-im="el.SubItem">
                                        <label class="checkbox-pretty inline menulvl2" ms-class="checked:im.issel>0?'checked':''" ms-attr-lid="im.ID">
                                            <input type="checkbox"><span>{{im.MenuTxt}}</span>
                                        </label>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </tbody>
            </table>

        </div>

    </div>
    </div>
   
<script type="text/javascript">

    

    var tempmodel = avalon.define({
        $id: "INFO",
        authData: [],
        modelData: { "ID": "0", "RoleName": "", "RoleDesp": "", "RoleAuth": "", "IsAdmin": "0" },
        inittemp: function (strId) {
            $.getJSON(ComFunJS.APIURL("BASE_GETAUTHMENU"), { P1: strId }, function (r) {
                if (r.error == "") {
                    tempmodel.authData = r.result;

                }
            })

            if (strId) {
                ComFunJS.getJSON("BASE_GETROLEMODEL", { "P1": strId }, function (r) {
                    if (r.error == "") {
                        tempmodel.modelData = r.result;


                    }

                })

            } else {
                ComFunJS.initForm();
            }

        },
        SaveData: function (dom, formtype, status) {
            var selAuth = "";
            $("#authDT").find("label.checked").each(function (index, item) {
                if (selAuth) {
                    selAuth += "," + $(item).attr("lid");
                } else {
                    selAuth = $(item).attr("lid");
                }
            })

            tempmodel.modelData.RoleAuth = selAuth;

            ComFunJS.postJSON("BASE_ADDROLE", { P1: JSON.stringify(tempmodel.modelData.$model) }, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");

                    top.ComFunJS.close();

                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }
            })
        }


    })

</script>

